const innerAudioContext = wx.createInnerAudioContext();


Page({


  /**
   * 页面的初始数据
   */
  data: {
        dataList:[],
        isRefresh: false

  },


  
  BGM: function (e) {
    let that = this;
    

    if (that.data.bgm) {
      that.setData({
        bgm: false,
      })
      innerAudioContext.pause(); /**  暂停音乐 */
      wx.showToast({
        title: '停止施法',
        icon: 'none',
        duration: 3000
      })

    } else {
      that.setData({
        bgm: true,
        bgmImgAni: "bgmImgAni"
      })
      // 播放音乐
      innerAudioContext.autoplay = true
      innerAudioContext.loop = true
      innerAudioContext.src = that.data.mp3[0];
      innerAudioContext.play();
      wx.showToast({
        title: '开始吟唱',
        icon: 'none',
        duration: 3000
      })

    }
  },

  clickImg: function(e){
    var src = e.currentTarget.dataset.src;
    let that = this;

    wx.previewImage({
      urls: [src],
      
    })
  },
  clickImg1: function(e){
    var src = e.currentTarget.dataset.src;
    let that = this;
    wx.previewImage({
      urls: [src],
    })
  },
  
  clickImg2: function(e){
    var src = e.currentTarget.dataset.src;
    let that = this;

    wx.previewImage({
      urls: [src],
    })
  },

 getData(num=8,page=0){
      wx.cloud.callFunction({
          
          name:"thinksList",
          data:{
              num:num,
              page:page,
          }
      }).then(res=>{
          var oldData=this.data.dataList
          var newData=oldData.concat(res.result.data);
          this.setData({
              dataList:newData,
              isRefresh: true
          })
      })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
        
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
    this.setData({
      dataList:[],

  })
  
    this.getData(8,0),

    wx.showToast({
      title: '刷新成功',
      image:'/image/cg.png',
      duration:1000,
    })

      wx.stopPullDownRefresh()

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
        wx.showLoading({
          title: '探寻中',
          duration:700,
        })

this.setData
        var page=this.data.dataList.length
        this.getData(2,page)

       
        
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})